layui.use(['form','layer','layedit','laydate','upload'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
         var id;
         var picUrl;
       	 $.ajax({
            type: "GET",
            headers: {
                token :  $.cookie('token')
            },
            url: api+"loms/mg/business/my",
            success: function(result){
            	tableData = result.data;
            	id = result.data.id;
            	picUrl = result.data.picUrl;
            	$('.shopPic').attr("src", tableData.picUrl);
                $('.name').val(tableData.name);
                $('.phone').val(tableData.phone);
                $('.shippingFee').val(tableData.shippingFee);
                $('.packageFee').val(tableData.packageFee);
                $('.minPrice').val(tableData.minPrice);
            }
        });    
	    

    var picurl=''; 
	$("#file").change(function () {
        var formDate = new FormData();
        formDate.append("file",$('#file')[0].files[0]);
        $.ajax({
            url: api1+"upload",
            data:formDate,
            cache: false,
            type:"POST",
            processData: false,
            contentType: false,
            success:function (data) {
                console.log(data);
                 $('.shopPic').attr('src', data);
                picurl = data;
//              console.log(picurl)
            }
        })
    })
	    
//
    form.on("submit(addActivity)",function(data){
        console.log(data);
        console.log(picurl);
            if(picurl !== ""){
            	picUrl = picurl;
            }
            $.ajax({
	            type: "POST",
	            headers: {
	                token :  $.cookie('token')
	            },
	            url: api+"loms/mg/business/update",
	            data: {
	            	id: id,
	                name: $('.name').val(),
                    phone: $('.phone').val(),
                    picUrl: picUrl,
                    shippingFee: $('.shippingFee').val(),
                    packageFee: $('.packageFee').val(),
                    minPrice: $('.minPrice').val()
	            },
	            success: function(result){
	            	console.log(result);
	            	if(result.code == 1){
	  		             top.layer.msg("店铺信息修改成功！");
		    		     setTimeout(function(){
					           parent.location.reload();
					      },1000);
	            	}
	            }
	        });
	        return false;
    })



});